window.onload = function () {
    document.getElementById("administrative").className = "add-nav-active";
    document.getElementById("meeting_reservation").className = "add_class";
    document.getElementById("meeting_management_ul").style.display = "inline-block";
    document.getElementById("jiantou2").className = "iconfont icon-jiantou-xia";
    document.getElementById("organizational_management_ul").style.display = "none";
    station_list()
};



function click_ul() {
    if (document.getElementById("jiantou").className === "iconfont icon-jiantou-shang"){
        document.getElementById("jiantou").className = "iconfont icon-jiantou-xia";
        document.getElementById("organizational_management_ul").style.display = "inline-block";
    }else {
        document.getElementById("jiantou").className = "iconfont icon-jiantou-shang";
        document.getElementById("organizational_management_ul").style.display = "none";
    }
}

function click_ul1() {
    if (document.getElementById("jiantou1").className === "iconfont icon-jiantou-shang"){
        document.getElementById("jiantou1").className = "iconfont icon-jiantou-xia";
        document.getElementById("gebruikersrol_ul").style.display = "inline-block";
    }else {
        document.getElementById("jiantou1").className = "iconfont icon-jiantou-shang";
        document.getElementById("gebruikersrol_ul").style.display = "none";
    }
}

function click_ul2() {
    if (document.getElementById("jiantou2").className === "iconfont icon-jiantou-shang"){
        document.getElementById("jiantou2").className = "iconfont icon-jiantou-xia";
        document.getElementById("meeting_management_ul").style.display = "inline-block";
    }else {
        document.getElementById("jiantou2").className = "iconfont icon-jiantou-shang";
        document.getElementById("meeting_management_ul").style.display = "none";
    }
}

function click_ul3() {
    if (document.getElementById("jiantou3").className === "iconfont icon-jiantou-shang"){
        document.getElementById("jiantou3").className = "iconfont icon-jiantou-xia";
        document.getElementById("issue_approval_ul").style.display = "inline-block";
    }else {
        document.getElementById("jiantou3").className = "iconfont icon-jiantou-shang";
        document.getElementById("issue_approval_ul").style.display = "none";
    }
}

// 加载我的申请列表
function station_list(sent_str, page) {
    page = page || 1;
    sent_str = sent_str || 1;
    document.getElementById("loading").style.display = "inline-block";
    var xhr = new XMLHttpRequest();
    var local_host = window.location.host;          // 获取当前IP
    xhr.open('post', "/administrative/meeting_reservation.html", true);
    xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
    xhr.send(sent_str+"&page="+String(page));
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                document.getElementById("loading").style.display = "none";
                var JsonDate = JSON.parse(xhr.responseText);
                create_table(JsonDate["count_num"], JsonDate["data"], page);
                pagenum(JsonDate["count_num"], page);
            }
        }
    };
}

function create_table(count_num, json_data, page) {
    var t_table = document.getElementById("t_table");
    deltr();
    if (json_data.length === 0){
        document.getElementById("img-display").style.display = "inline-block";
    }else {
        document.getElementById("img-display").style.display = "none";
    }
    for (var i=0; i<json_data.length; i++) {
        var tr = document.createElement("tr");
        var td = document.createElement("td");var td1 = document.createElement("td");var td2 = document.createElement("td");var td3 = document.createElement("td");var td4 = document.createElement("td");var td5 = document.createElement("td");
        var td6 = document.createElement("td");var td7 = document.createElement("td");var td8 = document.createElement("td");
        td.innerHTML = json_data[i]["meeting_room"];td.style.textAlign = "center";
        td1.innerHTML = json_data[i]["meeting_theme"];td1.title = json_data[i]["meeting_theme"];td1.style.width = "10%";td1.style.textAlign = "center";
        td2.innerHTML = json_data[i]["present"];td2.title = json_data[i]["present"];td2.style.width = "10%";td2.style.textAlign = "center";
        td3.innerHTML = json_data[i]["status"];td3.title = json_data[i]["status"];td3.style.width = "10%";td3.style.textAlign = "center";
        td4.innerHTML = json_data[i]["meeting_start"];td4.title = json_data[i]["meeting_start"];td4.style.width = "10%";td4.style.textAlign = "center";
        td5.innerHTML = json_data[i]["meeting_end"];td5.title = json_data[i]["meeting_end"];td5.style.width = "10%";td5.style.textAlign = "center";
        td6.innerHTML = json_data[i]["proposer"];td6.title = json_data[i]["proposer"];td6.style.width = "10%";td6.style.textAlign = "center";
        td7.innerHTML = json_data[i]["department"];td7.title = json_data[i]["department"];td7.style.width = "10%";td7.style.textAlign = "center";
        td8.innerHTML = json_data[i]["apply_time"];td8.title = json_data[i]["apply_time"];td8.style.width = "10%";td8.style.textAlign = "center";
        // td4.innerHTML = "<a href='#' onclick='revocation(" + json_data[i]["id"] + ", " + page + ")'>撤回</a> | <a href='"+json_data[i]["apply_url"]+"' target='_blank'>查看</a>";td4.style.textAlign = "center";td4.style.width = "10%";
        // td5.innerHTML = "<a href='modify_meeting.html?id="+json_data[i]["MeetingInfo_id"]+"' target='_blank'>编辑</a>";td5.style.textAlign = "center";td5.style.width = "10%";
        tr.appendChild(td);tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td5);
        tr.appendChild(td6);tr.appendChild(td7);tr.appendChild(td8);
        t_table.appendChild(tr);
    }

}

// 删除列表
function deltr(){
    var tb = document.getElementById('t_table');
    var rowNum=tb.rows.length;
    for (i=0;i<rowNum;i++) {
        tb.deleteRow(i);
        rowNum=rowNum-1;
        i=i-1;
    }
}


function pagenum(dataTotals, page) {
    page = page || 1;
    dataTotals = dataTotals || 0;
    new myPagination({
        id: 'pagination',
        curPage: page, //初始页码
        pageAmount: 20,  //每页多少条
        dataTotal: dataTotals, //总共多少条数据
        pageTotal:  Math.ceil(parseInt(dataTotals, 10)/20), //总页数
        pageSize: 5, //可选,分页个数
        showPageTotalFlag:true, //是否显示数据统计
        showSkipInputFlag:true, //是否支持跳转
        getPage: function (page) {
            station_list(sent_str='', page);
            document.getElementById("check_all").checked = false;
        }
    });
}

function revocation(ele_id, page) {
    document.getElementById("loading").style.display = "inline-block";
    var xhr = new XMLHttpRequest();
    var local_host = window.location.host;          // 获取当前IP
    xhr.open('post', "/technological/revocation", true);
    xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
    xhr.send("page="+String(page)+"&revocation_id="+String(ele_id)+"&type=meeting");
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                document.getElementById("loading").style.display = "none";
                var JsonDate = JSON.parse(xhr.responseText);
                create_table(JsonDate["count_num"], JsonDate["data"], page);
                pagenum(JsonDate["count_num"], page);
            }
        }
    };
}

